//
//  ZlModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit
enum ZlType: Int {
    
    case kg = 0
    case g
    case mg
    case ug
    case t
    case q
    case lb
    case oz
    case ct
    case gr
    case lt
    case st
    case yingdan
    case meidan
    case sts
    case dr
    case dan
    case jin
    case liang
    case qian
    case fen
}


class ZlModel: NSObject {
    let types = ["千克","克","毫克","微克","吨","公担","磅","盎司","克拉","格令","长吨","短吨","英担","美担","英石","打兰","担","斤","两","钱","分"]
    let signs = ["kg","g","mg","ug","t","q","lb","oz","ct","gr","lt","st","英担","美担","st","dr","担","斤","两","钱","分"]
    
    
    func kmTall(n: Double, type: ZlType, reverse: Bool = false) -> Double {
        var km3 = n
        switch type {
        case .kg:
            break
        case .g:
            km3 = reverse ? n / 1000: n * 1000
            break
        case .mg:
            km3 = reverse ? n / 1000000: n * 1000000
            break
        case .ug:
            km3 = reverse ? n / 1000000000: n * 1000000000
            break
        case .t:
            km3 = reverse ? n / 0.001: n * 0.001
            break
        case .q:
            km3 = reverse ? n / 0.01: n * 0.01
            break
        case .lb:
            km3 = reverse ? n / 2.2046226: n * 2.2046226
            break
        case .oz:
            km3 = reverse ? n / 35.2739619: n * 35.2739619
            break
        case .ct:
            km3 = reverse ? n / 5000: n * 5000
            break
        case .gr:
            km3 = reverse ? n / 15432.3583529: n * 15432.3583529
            break
        case .lt:
            km3 = reverse ? n / 0.0009842: n * 0.0009842
            break
        case .st:
            km3 = reverse ? n / 0.0011023: n * 0.0011023
            break
        case .yingdan:
            km3 = reverse ? n / 0.0196841: n * 0.0196841
            break
        case .meidan:
            km3 = reverse ? n / 0.0220462: n * 0.0220462
            break
        case .sts:
            km3 = reverse ? n / 0.157473: n * 0.157473
            break
        case .dr:
            km3 = reverse ? n / 564.3833912: n * 564.3833912
            break
        case .dan:
            km3 = reverse ? n / 0.02: n * 0.02
            break
        case .jin:
            km3 = reverse ? n / 2: n * 2
            break
        case .liang:
            km3 = reverse ? n / 20: n * 20
            break
        case .qian:
            km3 = reverse ? n / 200: n * 200
            break

        case .fen:
            km3 = reverse ? n / 500000: n * 500000
            break

            
        }
        return km3
    }

    
    func allChange(d: Double, type: ZlType) -> [String] {
        let km = kmTall(n: d, type: type, reverse: true)
        
        
        
        return ["\(kmTall(n: km, type: .kg))\(signs[0])","\(kmTall(n: km, type: .g))\(signs[1])",
                "\(kmTall(n: km, type: .mg))\(signs[2])","\(kmTall(n: km, type: .ug))\(signs[3])",
                "\(kmTall(n: km, type: .t))\(signs[4])","\(kmTall(n: km, type: .q))\(signs[5])",
                "\(kmTall(n: km, type: .lb))\(signs[6])","\(kmTall(n: km, type: .oz))\(signs[7])","\(kmTall(n: km, type: .ct))\(signs[8])","\(kmTall(n: km, type: .gr))\(signs[9])",
                "\(kmTall(n: km, type: .lt))\(signs[10])","\(kmTall(n: km, type: .st))\(signs[11])",
                "\(kmTall(n: km, type: .yingdan))\(signs[12])","\(kmTall(n: km, type: .meidan))\(signs[13])",
                "\(kmTall(n: km, type: .sts))\(signs[14])","\(kmTall(n: km, type: .dr))\(signs[15])",
                "\(kmTall(n: km, type: .dan))\(signs[16])","\(kmTall(n: km, type: .jin))\(signs[17])",
                "\(kmTall(n: km, type: .liang))\(signs[18])","\(kmTall(n: km, type: .qian))\(signs[19])","\(kmTall(n: km, type: .fen))\(signs[20])"]

    }


}
